package com.supermap.dataservice.expert.cq;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
import java.util.Map;

/**
 * @author aqua
 * @description
 * @date 2018年11月09 下午 4:33
 * @email 1301584033@qq.com
 */
@Mapper
public interface CqExpertProductMpper {

    /***
     * 获取重庆专家产品总数
     */
    @SelectProvider(type =CqExpertProductMpperSql.class ,method = "getCqExpertProductCountNumSQL")
    List<Map<String,Object>> getCqExpertProductCountNum(@Param("beginTime") String beginTime,@Param("endTime")String endTime,@Param("pageNum")String pageNum,@Param("pageSize")String pageSize);


    /**
     *根据区域专家产品详情
     * */
    @SelectProvider(type =CqExpertProductMpperSql.class,method ="getCqExpertProductListByAreaCodeSQL" )
    List<Map<String,Object>> getCqExpertProductListByAreaCode(@Param("beginTime")String beginTime,@Param("endTime")String endTime,@Param("areaCode") String areaCode);

    /**
     *
     *  根局大类ID获取决策服务产品详情
     * */
    @SelectProvider(type = CqExpertProductMpperSql.class,method = "getCqExpertProductListByAreaCodeDetailsSQL")
    List<Map<String,Object>> getCqExpertProductListByAreaCodeDetails(@Param("beginTime")String beginTime,@Param("endTime")String endTime,@Param("areaCode") String areaCode,@Param("baseClassId") String baseClassId);



    class CqExpertProductMpperSql{

        public String getCqExpertProductCountNumSQL(Map<String,Object> map){
            String beginTime=(String) map.get("beginTime");
            String endTime=(String) map.get("endTime");
            String pageNum=(String)map.get("pageNum");
            String pageSize=(String) map.get("pageSize");
            StringBuilder stringBuilder= new StringBuilder();
            stringBuilder.append("select t1.ID as deparId,t1.departname,if(count(t2.productID) is null,0,count(t2.productID)) as num,t1.depareacode from t_s_depart t1\n" +
                    "left join  t_expertproduct t2\n" +
                    "on t1.depareacode=t2.areacode ");
            if(beginTime!=null&&endTime!=null){
                stringBuilder.append("and t2.createTime between  '"+beginTime+"' and  '"+endTime+"' ");
            }
            stringBuilder.append("group by t1.ID  ");
            if(pageNum!=null&&pageSize!=null){
                stringBuilder.append("limit  "+pageNum+","+pageSize+" ");
            }
            return  stringBuilder.toString();
        }

        public String getCqExpertProductListByAreaCodeSQL(Map<String,Object> map){
            String beginTime=(String) map.get("beginTime");
            String endTime=(String) map.get("endTime");
            String areaCode=(String) map.get("areaCode");
            StringBuilder stringBuilder= new StringBuilder();
            return  "";
        }


        public String getCqExpertProductListByAreaCodeDetailsSQL(Map<String,Object> map){
            String beginTime=(String) map.get("beginTime");
            String endTime=(String) map.get("endTime");
            String pageNum=(String)map.get("pageNum");
            String pageSize=(String) map.get("pageSize");
            return  "";
        }

    }
}
